﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;

using eSYSU.Data.DataAccess;
using eSYSU.Web.Entity;
using eSYSU.Web.Interface;


namespace eSYSU.Web.Business
{
	/// <summary>
	/// 分类的业务类
	/// </summary>
	public class CatalogService
	{
		public CatalogService()
		{
			//
			//TODO: 在此处添加构造函数逻辑
			//
		}


		/// <summary>
		/// 插入一条分类记录
		/// </summary>
		/// <param name="catalog">分类模型对象</param>
		public static void CollegeInsert(Catalog catalog)
		{
			IDictionary<string, object> parmsDic = new Dictionary<string, object>();
			parmsDic.Add("@CName", catalog.Name);
			parmsDic.Add("@CBrief", catalog.Brief);
			parmsDic.Add("@CLogo", catalog.Logo);
			parmsDic.Add("@COrder", catalog.OrderIndex);

			SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.StoredProcedure, "proc_College_Insert", parmsDic);
		}


		/// <summary>
		/// 获取指定分类的记录（ID为零则获取全部分类记录）
		/// </summary>
		/// <param name="catalogId">分类编号（ID为零则获取全部分类记录）</param>
		/// <returns>DataTable对象</returns>
		public static DataTable GetCatalogs(int catalogId)
		{
			if (catalogId > -1)
			{
				IDictionary<string, object> parmsDic = new Dictionary<string, object>();
				parmsDic.Add("@_id", catalogId);

				return SqlHelper.GetDataTable(SqlHelper.ConnString, CommandType.StoredProcedure, "proc_College_Get", parmsDic);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 创建分类Logo的缩略图
		/// </summary>
		/// <param name="sOriginalLogoPath">用于生成缩略图的Logo源图地址</param>
		/// <param name="sDestinationLogoPaths">缩略图生成路径（包含扩展名）的字符串数组</param>
		/// <param name="iSize">缩略图的尺寸（与路径数组长度要一致）</param>
		/// <returns>生成结果</returns>
		public static bool CreateLogoThumbnail(string sOriginalLogoPath, string[] sDestinationLogoPaths, int[,] iSize)
		{
			try
			{
				for (int i = 0; i < sDestinationLogoPaths.Length; i++)
				{
					eSYSU.Web.Common.ImageHelper.CreateThumbnail(sOriginalLogoPath, sDestinationLogoPaths[i], iSize[i, 0], iSize[i, 1]);
				}
				return true;
			}
			catch
			{
				return false;
			}
		}
	}
}